#!/bin/bash

# RuoYi-Vue Docker部署构建脚本

# 设置项目根目录
PROJECT_ROOT=".."

# 构建后端jar包
echo "开始构建后端jar包..."
cd $PROJECT_ROOT
mvn clean package -Dmaven.test.skip=true

if [ $? -ne 0 ]; then
  echo "后端jar包构建失败"
  exit 1
fi

echo "后端jar包构建完成"

# 构建前端静态文件
echo "开始构建前端静态文件..."
cd $PROJECT_ROOT/ruoyi-ui
npm install
npm run build:prod

if [ $? -ne 0 ]; then
  echo "前端静态文件构建失败"
  exit 1
fi

echo "前端静态文件构建完成"

# 复制构建产物到docker-deployment目录
echo "复制构建产物..."
cd ../docker-deployment

cp $PROJECT_ROOT/ruoyi-admin/target/ruoyi-admin.jar ./backend/app.jar

cp -r $PROJECT_ROOT/ruoyi-ui/dist ./frontend/

echo "构建产物复制完成"

echo "启动Docker容器..."
docker-compose up -d

echo "部署完成！"
echo "前端界面: http://localhost:80"
echo "后端接口: http://localhost:8080"
echo "Druid监控: http://localhost:8080/druid (用户名: ruoyi, 密码: 123456)"